package demo.android.myapplication.demos.animation

import android.animation.Keyframe
import android.animation.ObjectAnimator
import android.animation.PropertyValuesHolder
import android.animation.TypeEvaluator
import android.content.Context
import android.graphics.*
import android.util.AttributeSet
import android.view.View
import androidx.core.graphics.plus
import cn.android.basic.centerX
import cn.android.basic.centerY
import cn.android.basic.dp

/**
 * <br>createBy Gw
 * <br>createTime: 2021/7/9 13:55
 * ObjectAnimator
 * PropertyValuesHolder
 * Keyframe
 */
class CircleView @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {
    private val paint = Paint(Paint.ANTI_ALIAS_FLAG)
    var radius = 50.dp
        set(value) {
            field = value
            invalidate()
        }

    override fun onAttachedToWindow() {
        super.onAttachedToWindow()
        val animator = ObjectAnimator.ofFloat(this, "radius", 150.dp)
        animator.startDelay = 1000
        animator.start()
    }

    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        canvas.drawCircle(centerX, centerY, radius, paint)
    }
    //       | inˈvaləˌdāt |
}